<?php defined('_VALID_MOS') or die('Direct Access to this location is not allowed.');

/*
 * Copyright Copyright (C) 2007 Alain Georgette. All rights reserved.
 * Copyright Copyright (C) 2006 Frantisek Hliva. All rights reserved.
 * License http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 *
 * !JoomlaComment is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * !JoomlaComment is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA  02110-1301, USA.
 */

function com_install()
{
    global $mosConfig_absolute_path, $database;
    $adminDir = dirname(__FILE__);
	require_once("$mosConfig_absolute_path/administrator/components/com_comment/library.comment.php");
    require_once("$mosConfig_absolute_path/components/com_comment/joscomment/utils.php");
    require_once("$mosConfig_absolute_path/administrator/components/com_comment/class.config.comment.php");
?>
	<table class="adminheading" cellpadding="4" cellspacing="0" border="0">
      <tr>
        <td>
<?php
	$msgstart = "<h2>There was a problem with your installation</h2>";
	$msgend = "<h2>Please, contact the <a target=\"_blank\" href=\"http://joomlacode.org/gf/project/joomagecomment\">support</a>."
			. "<br/>Thanks.</h2>";

	if (!josTableUtils::existsTable('#__comment')) {
	    /* one day, when param will be in database we could set here or not complete_uninstall param */
	}
		
	/*
	 * check mambot path is writable
	 */       
    if (!is_writable("$mosConfig_absolute_path/mambots/content/")) {
		$msgend = "<h2><p>Please:</p>" .
				"<ul>" .
				"	<li>Uninstall !JoomlaComment</li>" .
				"	<li>Modify the file permissions if needed</li>" .
				"	<li>Reinstall</li>" .
				"</ul>" .
				"<br/>Thanks.</p>" .
				"</h2>";
        echo $msgstart . "<p>The directory \"$mosConfig_absolute_path/mambots/content/\" is not writeable</p>". $msgend;
        return false;
    }

	$install_log = "";
    if (!josInstall::checkDatabase($install_log)) {
    	echo $msgstart ."<p>". $install_log ."</p>". $msgend;
    	return false;
    }

	$install_log = "Installation of joscomment mambot<br />";
    @rename($adminDir . "/plugin/joscomment.php", "$mosConfig_absolute_path/mambots/content/joscomment.php");
    @rename($adminDir . "/plugin/joscomment.xml", "$mosConfig_absolute_path/mambots/content/joscomment.xml");

    $database->setQuery("INSERT INTO `#__mambots` (`name`, `element`, `folder`, `access`, `ordering`, `published`, `iscore`, `client_id`, `checked_out`, `checked_out_time`, `params`) VALUES ('!JoomlaComment', 'joscomment', 'content', 0, 0, 1, 0, 0, 0, '0000-00-00 00:00:00', '');");
	if(!$result = $database->query()) {
    	$install_log .= "Mambot install error: " . $database->stderr() . "<br /><br />"; 
    	echo $msgstart ."<p>". $install_log ."</p>". $msgend;
    	return false;
	}   

   //add new admin menu images
    $database->setQuery("UPDATE #__components SET admin_menu_img='../components/com_comment/joscomment/images/logoicon.png' " .
    					"  WHERE admin_menu_link='option=com_comment'");
	$database->query();
    $database->setQuery("UPDATE #__components SET admin_menu_img='js/ThemeOffice/edit.png' " .
    					"  WHERE admin_menu_link='option=com_comment&task=comments'");
	$database->query();
    $database->setQuery("UPDATE #__components SET admin_menu_img='js/ThemeOffice/config.png' " .
    					"  WHERE admin_menu_link='option=com_comment&task=settings'");
	$database->query();
    $database->setQuery("UPDATE #__components SET admin_menu_img='js/ThemeOffice/controlpanel.png' " .
    					"  WHERE admin_menu_link='option=com_comment&task=importcomment'");
	$database->query();
	$database->setQuery("UPDATE #__components SET admin_menu_img='js/ThemeOffice/credits.png' " .
						"   WHERE admin_menu_link='option=com_comment&task=about'");
	$database->query();
?>
       </td>
      </tr>
      </table>
<?php 
	
	viewAbout(); 
}
?>

